//导入自定义验证规则的包
const joi = require('@hapi/joi')

//定义用户名和密码的验证规则
const username = joi.string().alphanum().min(1).max(10).required()
const password = joi.string().pattern(/^[\S]{6,12}$/).required()

//定义 id nickname email的验证规则  required必传
const id = joi.number().integer().min(1).required()
const nickname = joi.string().required()
const email = joi.string().required()
//定义验证头像的规则
const avatar = joi.string().dataUri().required()

//定义验证注册和登录表单数据的规则对象
exports.reg_login_schema = {
    body: {
        username,
        password
    }
}

exports.update_userInfo_schema = {
    body: {
        id,
        nickname,
        email
    }
}
//定义新密码与旧密码的验证规则  更新密码
exports.updatepwt = {
    body: {
        oldPwd: password,
        //ref 必须相同  not 取反  concat合并验证规则
        newPwd: joi.not(joi.ref("oldPwd")).concat(password)
    }
}
exports.update_avatar_schema = {
    body: { avatar }
}
